<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../commons/taglibs.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>detail</title>
    <link href="${ctx}/js/layui/css/layui.css"  rel="stylesheet" type="text/css"/>
</head>
<body>
<form class="layui-form layui-form-pane"  >
    <input type="text" name="id" value="${pd.id}" hidden>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名：</label>
        <div class="layui-input-block">
            <input type="text" name="loginname" value="${pd.loginname}" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密 码：</label>
        <div class="layui-input-inline">
            <input type="password" name="password" value="${pd.password}" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">隐藏密码</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓 名：</label>
        <div class="layui-input-block">
            <input type="text" name="realname"  value="${pd.realname}" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部 门：</label>
        <div class="layui-input-inline">
            <select id="departmentid" name="departmentid" lay-verify="required" lay-filter="dept" lay-search>
                <option value="" ></option>
                <option value="1" <c:if test="${pd.departmentid == '1'}">selected</c:if> >研发部</option>
                <option value="2">运营部</option>
                <option value="3">运维部</option>
                <option value="4">测试部</option>
                <option value="5">行政部</option>
                <%--<c:forEach items="${deptList}" var="dept">
                    <option value="${dept.id }" <c:if test="${dept.id == gridData.departmentid }">selected</c:if>>${dept.name}</option>
                </c:forEach>--%>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角 色：</label>
        <!-- 对于列表的情况下，应通过后台获取list列表-->
        <div class="layui-input-inline">
            <select id="roleid" name="roleid" lay-verify="required" lay-filter="role" lay-search>
                <option value=""></option>
                <option value="1" <c:if test="${pd.roleid == '1'}">selected</c:if> >超管</option>
                <option value="2">编辑人员</option>
                <option value="3">审核人员</option>
                <option value="4">日常管理</option>
                <option value="5">运维管理</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分 类：</label>
        <div class="layui-input-block">
            <input type="checkbox" name="categoryid" value="1" title="电影" <c:if test="${fn:contains(pd.categoryid,'1')}">checked</c:if>  >
            <input type="checkbox" name="categoryid" value="2" title="电视剧" <c:if test="${fn:contains(pd.categoryid,'2')}">checked</c:if> >
            <input type="checkbox" name="categoryid" value="3" title="综艺" <c:if test="${fn:contains(pd.categoryid,'3')}">checked</c:if> >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱:</label>
        <div class="layui-input-block">
            <input type="text" name="email" value="${pd.email}" placeholder="请输入邮箱" autocomplete="off" class="layui-input" lay-verify="email" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状 态：</label>
        <div class="layui-input-block">
            <c:if test="${pd.status == '1'}"><input type="checkbox" id="status" name="status" lay-skin="switch" lay-filter="switchStatus" lay-text="ON|OFF" value="${pd.status}" checked> </c:if>
            <c:if test="${pd.status == '0'}"><input type="checkbox" id="status" name="status" lay-skin="switch" lay-filter="switchStatus"lay-text="ON|OFF" value="${pd.status}" > </c:if>
            <c:if test="${pd.status == null}"><input type="checkbox" id="status" name="status" lay-skin="switch" lay-filter="switchStatus" lay-text="ON|OFF" value="1" checked> </c:if>
            <!--OFF状态时为不选中-->
        </div>
    </div>
    <div class="layui-form-item">
        <!-- 对于状态类型，没有列表的情况下，可以在页面上设置初始值-->
        <label class="layui-form-label">性 别：</label>
        <div class="layui-input-block">
            <input type="radio" name="gender" value="1" title="男"  <c:if test="${pd.gender == '1' || pd.gender == null}">checked</c:if> >
            <input type="radio" name="gender" value="2" title="女"  <c:if test="${pd.gender == '2'}">checked</c:if>>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="${ctx}/js/layui/layui.js"></script>
<script>
    layui.use('form', function(){
        var form = layui.form
            ,$ = layui.$;

        var rolename ;
        var categoryids ;
        var categorynames ;
        var departmentname ;
        form.on('select(role)', function(data){
            rolename = $("#roleid option:selected").text();
        });

        form.on('select(dept)', function(data){
            departmentname = $("#departmentid option:selected").text();
        });

        //监听指定开关
        form.on('switch(switchStatus)', function(data){
            if(this.checked == true){
                $('#status').val(1);
            }else{
                $('#status').val(0);
            }
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            categoryids = '';//每次初始，防止重复叠加数据
            categorynames = '';
            $("input:checkbox[name='categoryid']:checked").each(function() { // 遍历name=categoryid,需考虑取消选中问题
                if (categoryids == ''){
                    categoryids =  $(this).val();
                } else {
                    categoryids += ',' + $(this).val();

                }
                if (categorynames == '') {
                    categorynames = $(this).attr('title');
                } else {
                    categorynames += ',' + $(this).attr('title');
                }
            });

            if (categoryids != null && categoryids != ''){
                data.field.categoryid = categoryids;
            }
            if (categorynames != null && categorynames != ''){
                data.field.categoryname = categorynames;
            }
            if (rolename != null && rolename != '') {
                data.field.rolename = rolename;
            }
            if(departmentname != null && departmentid != ''){
                data.field.departmentname = departmentname;
            }
            //console.log(data.field);
            //console.log(categoryids);
            //console.log(categorynames);
            //console.log("status:"+$('#status').val());
            if ($('#status').val() ==0) {
                //status为0时，表示没有选中，不会传值
                data.field.status = 0;
            }

            $.ajax({
                url: '${ctx}/sysadmin/${method}',
                data: data.field,
                datatype: "json",
                type: 'post',
                success: function (e) {   //成功后回调
                   if(e.status == 200){
                       layer.alert('保存成功:'+e.msg, {
                           title:'提示'
                           ,icon:1
                           ,closeBtn: 0
                       }, function(){
                           var index = parent.layer.getFrameIndex(window.name);
                           parent.layer.close(index);
                       });
                   } else {
                       layer.alert('保存失败:'+e.msg, {
                           title:'提示'
                           ,icon:2
                           ,closeBtn: 0
                       }, function(){
                           layer.close(layer.index);
                           var index = layer.load();
                           layer.close(index);
                       });
                   }
                },
                error: function(e){    //失败后回调
                    layer.alert('保存失败:'+e.msg, {
                        title:'提示'
                        ,icon:2
                        ,closeBtn: 0
                    }, function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                },
                beforeSend: function(){  //发送请求前调用，可以放一些"正在加载"之类额话
                    layer.load(1);
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
